#include <normalRadioSelector.h>

namespace lgb_gtk
{

  NormalRadioSelector::NormalRadioSelector()
  {
    isHorizontal = true;
    group = NULL;
  }

  NormalRadioSelector::~NormalRadioSelector()
  {

  }

  int NormalRadioSelector::Init()
  {
    if(hasInit)
      return 1;

    int size = texts.size();
    tmpX = x;
    tmpY = y;

    for(int i = 0; i < size ; i++ )
      {
	GtkWidget *button = gtk_radio_button_new_with_label(group , texts[i].c_str());
	group = gtk_radio_button_get_group((GtkRadioButton*)button);
	buttons.push_back(button);
	int tWidth = texts[i].size()*7 + 27;
	goo_canvas_widget_new( canvas , button , tmpX , tmpY , tWidth , 30 , NULL); 
	if(isHorizontal)
	  tmpX = tmpX + tWidth + 5;
	else
	  tmpY = tmpY + 30;
      }

    hasInit = true;
    
    return 0;
  }

  int NormalRadioSelector::AddOptionWithText(string option)
  {
    if(hasInit)
      {
	GtkWidget *button = gtk_radio_button_new_with_label(group , option.c_str());
	group = gtk_radio_button_get_group((GtkRadioButton*)button);
	buttons.push_back(button);
	int tWidth = option.size()*7 + 27;
        goo_canvas_widget_new( canvas , button , tmpX , tmpY , tWidth , 30 , NULL);
	if(isHorizontal)
          tmpX = tmpX + tWidth + 5;
        else
	tmpY = tmpY + 30;
      }
    texts.push_back(option);

    return 0;
  }

  int NormalRadioSelector::Clean()
  {
    
    return 0;
  }

  int NormalRadioSelector::CurrentSelect() 
  {
    int size = buttons.size();
    for(int i = 0; i < size ; i ++)
      if( gtk_toggle_button_get_active((GtkToggleButton *)buttons[i]) )
	 return i;
    return -1;
  }

}
